package com.hz.ws;

import com.hz.base.beans.vo.CommonResult;
import com.hz.beans.user.entity.TCounselling;
import com.hz.beans.user.entity.TReply;
import com.hz.interfaces.user.inf.ITConsuReplyInterface;
import com.hz.interfaces.user.inf.ITCounsellingInterface;
import com.hz.interfaces.user.inf.ITReplyInterface;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;

/**
 * @author mcz
 * @Date 2018/10/19 14:41
 * @Description 回复表控制器
 * @Version 1.0
 */
@Api(tags = "回复咨询",description = "CURD")
@Controller
@RequestMapping("/reply")
public class ReplyController {
    @Autowired
    private ITReplyInterface itReplyInterface;

    @Autowired
    private ITCounsellingInterface itCounsellingInterface;



    @ApiOperation(value="添加咨询回复信息", notes="根据咨询ID回复")
    @ApiImplicitParam(name = "回复实体类", value = "", required = true, dataType = "Long", paramType = "query")
    @RequestMapping(value = "/replyConsu/{consuId}" ,method = {RequestMethod.POST,RequestMethod.GET})
    public String addTReplyConsu(@PathVariable(name = "consuId")Long consuId,@RequestBody TReply tReply, ModelMap modelMap){
        itReplyInterface.addTReplyConsu(tReply,consuId);
        CommonResult<TCounselling> queryResult=itCounsellingInterface.queryTCounselling(consuId);
        List<TReply> replyResult=itReplyInterface.queryTReplyAndQuesList(queryResult.getData());
        modelMap.addAttribute("reply",replyResult);
        modelMap.addAttribute("results",queryResult);
        return "page/requireDetail";
    }


    @RequestMapping(value = "/reply2Reply/getReplyFormPage" ,method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView getReplyFormPage(String replyPid,String consuId){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("replyPid",replyPid);
        modelAndView.addObject("consuId",consuId);
        modelAndView.setViewName("page/getReplyFormPage");
        return  modelAndView;
    }

    @ApiOperation(value="添加回复的回复信息", notes="根据上级回复ID回复")  //----->json  ajax
    @ApiImplicitParam(name = "回复实体类", value = "", required = true, dataType = "Long", paramType = "body")
    @RequestMapping(value = "/reply2Reply" ,method = {RequestMethod.POST})
    @ResponseBody
    public String reply2Reply(@RequestBody String param){
        JSONObject object=JSONObject.fromObject(param);
        return  itReplyInterface.addTReply2Reply(object);
    }




}
